﻿/**
* MVCHandler.cs
* 
**/
using System;
using System.Web;
using System.Web.SessionState;

using Yawf.Core;
using Yawf.Security;
using Yawf.Web.Managers;

namespace Yawf.Web.HttpHandlers {
	/// <summary>
	/// A MVC Http Handler, here is we all good stuff happens
	/// 
	/// </summary>
	public class MVCHandler : IHttpHandler,IRequiresSessionState {
		MVCController mvcController = null;
		/// <summary>
		/// Is Reusable Property, always returns true, cause we can
		/// handle being in a thread pool
		/// </summary>
		public bool IsReusable {get{return true;}}

		/// <summary>
		/// Gets the MVC Controller that really do all the http handling
		/// </summary>
		/// <param name="context">HttpContext to use</param>
		/// <returns>A MVCController object</returns>
		public MVCController GetMVCController(HttpContext context) {
			Initializer initializer;

			if (mvcController != null) {
				return mvcController;
			}

			// Get VCG Framework initializer
			initializer = Initializer.Instance;
			if (initializer != null && initializer.ContainsObject("mvcController")) {
				mvcController = (MVCController)initializer.GetObject("mvcController");
			}

			return mvcController;
		}								// GetMVCController

		/// <summary>
		/// A http handler that really uses a MVCController object to 
		/// handle all http stuff, this is just a wrapper class cause
		/// the MVCController is created via Spring.NET and injected with 
		/// all classes that really do the stuff
		/// </summary>
		/// <param name="context">HttpContext to use</param>
		public void ProcessRequest(HttpContext context) {
			GetMVCController(context).ProcessRequest(context);
		}												// ProcessRequest

	}
}
